package aps

import cn.hutool.json.JSONUtil
import glory.xxd.Utils

/**
 * PDA 提交录入作业过程中录入数据
 */
class SubmitInputDataController {

    def commentService

    def index() {

        try {
            def OPID = params.OPID ?: ""
            def EqpId = params.EqpId ?: ""
            def SkipReason = params.SkipReason?:""

            def InputDataType = params.InputDataType ?: ""

            String logUUID = Utils.getUUID();

            def header = [MESSAGENAME: "SubmitInputData", TRANSACTIONID: logUUID, USERNAME: "EAP"]
            header = "<Header>${Utils.getXmlByJSONHtml(header)}</Header>"

//            //获取InputDataList
//            def InputDataList = """ [{
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}, {
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "清洁线夹",
//\t\t"DATANAME": "清洁线夹",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "清洁线夹",
//\t\t\t\t"DATANAME": "清洁线夹",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"ISNULL": "N"
//\t\t\t}]
//\t\t}
//\t}
//}]"""

//            def InputDataList ="""
//{
//\t"INPUTDATA": {
//\t\t"DATACNNAME": "抽检结果",
//\t\t"DATANAME": "抽检结果",
//\t\t"INPUTDATAS": {
//\t\t\t"INPUTDATA": [{
//\t\t\t\t"DATACNNAME": "抽检结果",
//\t\t\t\t"DATANAME": "抽检结果",
//\t\t\t\t"DATATYPE": 2,
//\t\t\t\t"DATATYPEDETAIL": "NG1;NG2;NG3",
//\t\t\t\t"DATAVALUE": "OK",
//\t\t\t\t"EQPID": "1FW0822",
//\t\t\t\t"ISNULL": "Y",
//\t\t\t\t"position": 0
//\t\t\t}]
//\t\t}
//\t}
//}
//"""
            def InputDataList =params.InputDataList
            def isJsonArray = JSONUtil.isJsonArray(InputDataList)
            print InputDataList.getClass()
            if (isJsonArray) {
                InputDataList = Utils.getXmlByJSONArray(InputDataList)
            } else {
                InputDataList = Utils.getXmlByJSONHtml(InputDataList)
            }

            //组装body
            def body = [EqpId: EqpId, OPID: OPID,SkipReason:SkipReason, InputDataType: InputDataType, INPUTDATALIST: InputDataList]

            body = "<Body>${Utils.getXmlByJSONHtml(body)}</Body>"
            def xml = "<Request>${header}${body}</Request>"

            def json = commentService.getJsonByObjectForTopic2Queue(logUUID, xml)

            render json
        } catch (Exception e) {
            e.printStackTrace()
        }
    }

}